package com.itbaizhan.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_common.pojo.Category;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.CategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告控制器
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
	
	@DubboReference
	private CategoryService categoryService;
	
	/**
	 * 增加广告
	 * @param category
	 */
	@PostMapping("/add")
	public BaseResult add(@RequestBody Category category){
		categoryService.add(category);
		return BaseResult.ok();
	}
	
	/**
	 * 修改广告
	 * @param category
	 */
	@PutMapping("/update")
	public BaseResult update(@RequestBody Category category){
		categoryService.update(category);
		return BaseResult.ok();
	}
	
	/**
	 * 修改广告状态
	 *
	 * @param id   广告id
	 * @param status 广告状态 0:未启用 1:启用
	 * @return 操作结果
	 */
	@PutMapping("/updateStatus")
	public BaseResult updateStatus(Long id, Integer status) {
		categoryService.updateStatus(id,status);
		return BaseResult.ok();
	}
	
	
	/**
	 * 删除广告
	 * @param ids
	 */
	@DeleteMapping("/delete")
	public BaseResult delete(Long[] ids){
		categoryService.delete(ids);
		return BaseResult.ok();
	}
	
	/**
	 * 根据id查询广告
	 * @param id
	 */
	@GetMapping("/findById")
	public BaseResult<Category> findById(Long id){
		Category category = categoryService.findById(id);
		return BaseResult.ok(category);
	}
	

	
	/**
	 * 分页查询广告
	 * @param page
	 * @param size
	 * @return
	 */
	@GetMapping("/search")
	public BaseResult<Page<Category>> search(int page, int size){
		Page<Category> categoryPage = categoryService.search(page, size);
		return BaseResult.ok(categoryPage);
	}

}
